package com.hq.ims.userpc.controller;

import com.hq.ims.data.entityenum.EnumBusinessTypeStatus;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.utils.WebExpandUtils;
import com.hq.ims.data.vo.statistics.PublishStatisticsSearchVo;
import com.hq.ims.data.vo.statistics.PublishStatisticsVo;
import com.hq.ims.data.vo.statistics.TrackStatisticsVo;
import com.hq.ims.data.service.other.BusiInfoStatisticsService;
import com.hq.ims.data.vo.statistics.statisticsEnum.EnumDimension;
import com.hq.utils.util.StringUtils;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Objects;

/**
 * @author yinzhangxiao
 * @date 2024/11/1 13:42
 * @ClassName BusiInfoStatisticsController
 **/
@Api(tags = "经营信息统计")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_USER_PC_URL_PREFIX + "/busiInfoStatistics")
public class BusiInfoStatisticsController {
    @Resource
    private BusiInfoStatisticsService busiInfoStatisticsService;

    @ApiOperation(value = "经营信息发布统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/pubulishStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<PublishStatisticsVo> pubulishStatistics(@RequestBody PublishStatisticsSearchVo searchVo) {
        //未指定查询组织则统计当前登录人所在组织
        if (StringUtils.isEmpty(searchVo.getOrgId())) {
            searchVo.setOrgId(WebExpandUtils.getHeadCompanyId());
        }
        //统计维度不传默认为天
        if (Objects.isNull(searchVo.getDimension())) {
            searchVo.setDimension(EnumDimension.Day);
        }
        //统计信息类型范围
        EnumBusinessTypeStatus[] infoType = {
                EnumBusinessTypeStatus.ProfessionRelevance,
                EnumBusinessTypeStatus.AllUserBusiness,
                EnumBusinessTypeStatus.ExternalStatement
        };
        searchVo.setInfoTypeList(Arrays.asList(infoType));
        return ReturnVo.buildSuccess(busiInfoStatisticsService.pubulishStatistics(searchVo));
    }

    @ApiOperation(value = "经营信息跟踪统计", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/trackStatistics", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<TrackStatisticsVo> trackStatistics(@GetJsonValue(zh = "组织Id", required = false) String orgId) {
        //未指定查询组织则统计当前登录人所在组织
        if (StringUtils.isEmpty(orgId)) {
            orgId = WebExpandUtils.getHeadCompanyId();
        }
        return ReturnVo.buildSuccess(busiInfoStatisticsService.trackStatistics(orgId));
    }

}
